import routes from 'uni-router-routes' //由unplugin-uni-router/vite根据pages.json生成
import { createRouter } from 'uniapp-router-next'
import { useStore } from '@/store/index.js'



const router = createRouter({
  routes: [
    ...routes,
  ],
  //@ts-ignore
  platform: process.env.UNI_PLATFORM,
  h5: {}
})

router.beforeEach(async (to, form, next) => {
  let token = uni.getStorageSync('token')
  if(token) {
    // if(whitlist.includes(to.path)) {
    //   return next({ path: '/pages/index/index'})
    // }
    // let userInfoData = useStore().user.userInfo
    // if(Object.keys(userInfoData).length == 0) {
    //   try {
    //     const res = await userInfo();
    //     if(res?.code == '0000') {
    //       useStore().user.SET_USERINFO(res?.data)
    //       return next()
    //     } else {
    //       return uni.showModal({
    //         title: '提示',
    //         content: '获取用户信息失败，请重新登录',
    //         showCancel: false,
    //         confirmColor: theme['$uni-color-primary'],
    //         success: function() {
    //           uni.clearStorageSync();
    //           uni.reLaunch({
    //             url: '/sub_user/pages/login/login'
    //           });
    //         }
    //       })
    //     }
    //   }catch(err) {
    //     return uni.showModal({
    //       title: '提示',
    //       content: '获取用户信息失败，请重新登录',
    //       showCancel: false,
    //       confirmColor: theme['$uni-color-primary'],
    //       success: function() {
    //         uni.clearStorageSync();
    //         uni.reLaunch({
    //           url: '/sub_user/pages/login/login'
    //         });
    //       }
    //     })
    //   }
    // }
    return next()
  }
  
  return next()
})
  
router.afterEach((to, form) => {})

export default router